begin
 require 'rack-html5'
rescue LoadError
 puts "Gem rack-html5 is not available. Install it with: sudo gem install rack-html5"
end

module RackHtml5RailsHelper
  
  # Defines a method and a helper for each header the rack-html5 gem sets.
  # Example: <tt>browser_supports_canvas?</tt> will return true if the <tt>HTTP_X_SUPPORTS_HTML5_CANVAS</tt> header is set.
  def self.included(base)
    features = [:wysiwyg, :classname, :elements, :canvas, :messaging, :audio, :video, :textapi, :draganddrop, :offline, :forms, :svg]
    
    features.each do |header|    
      method_name = "browser_supports_#{header}?".to_sym
      define_method method_name do
        request.headers.has_key?("HTTP_X_SUPPORTS_HTML5_#{header.to_s.upcase}")    
      end
          
      base.send(:helper_method, method_name)
    end
  end
  
end